package direct;

import com.rabbitmq.client.*;
import utils.RabbitMQUtils;

import java.io.IOException;

/**
 * @author lucine
 * @version 1.0 2021/6/20 11:13
 */
public class Custormer2 {
    public static void main(String[] args) throws Exception {
        //获取链接对象
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();

        //绑定交换机
        channel.exchangeDeclare("testDirect","direct");
        //临时队列创建
        String queueName = channel.queueDeclare().getQueue();
        //绑定交换机和队列
        channel.queueBind(queueName,"testDirect","error");
        channel.queueBind(queueName,"testDirect","warning");
        channel.queueBind(queueName,"testDirect","info");

        channel.basicConsume(queueName, true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1"+new String(body));
            }
        } );

//        RabbitMQUtils.cloneConnectionAndChannel(channel,connection);
    }
}
